package com.chuantou.yuba.ui.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.chuantou.yuba.R;
import com.chuantou.yuba.api.to.TrendsCommentTO;
import com.chuantou.yuba.api.to.TrendsTO;
import com.chuantou.yuba.ui.fragment.TrendsFragment;
import com.chuantou.yuba.util.ProfileLinkMovementMethod;

public class TrendsCommentView extends FrameLayout implements android.view.View.OnClickListener {
	private TrendsCommentTO mComment;
	private TrendsTO mTrends;
	private TrendsFragment mFragment;
	private TextView mCommentView;

	public TrendsCommentView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		setupViews();
	}

	public TrendsCommentView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupViews();
	}

	public TrendsCommentView(Context context) {
		super(context);
		setupViews();
	}

	private void setupViews() {
		setClickable(true);
		setOnClickListener(this);
		setBackgroundResource(R.drawable.trends_comment_text_bg);
		mCommentView = new TextView(getContext());
		mCommentView.setTextColor(Color.BLACK);
		mCommentView.setClickable(true);
		mCommentView.setPadding(0, 0, 0, 4);
		mCommentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
		mCommentView.setMovementMethod(ProfileLinkMovementMethod.getInstance());
		addView(mCommentView);
	}

	public TrendsCommentTO getComment() {
		return mComment;
	}

	public void setComment(TrendsCommentTO mComment) {
		this.mComment = mComment;
	}

	public void setTrendsFragment(TrendsFragment fragment) {
		this.mFragment = fragment;
	}

	public TrendsTO getTrends() {
		return mTrends;
	}

	public void setTrends(TrendsTO mTrends) {
		this.mTrends = mTrends;
	}

	public void setText(CharSequence text) {
		mCommentView.setText(text);
	}

	@Override
	public void onClick(View v) {
		if (mComment != null && mFragment != null) {
			mFragment.showReplyPopup(mTrends, mComment.getUid(), mComment.getNickname());
		}
	}
}
